package com.winderinfo.yikaotianxia.ui.banxing;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.api.Api;
import com.winderinfo.yikaotianxia.core.base.BaseActivity;
import com.winderinfo.yikaotianxia.core.mvp.Contract;
import com.winderinfo.yikaotianxia.core.mvp.Presenter;
import com.winderinfo.yikaotianxia.ui.home.ZhuanYeBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ClassTypeActivity extends BaseActivity implements Contract.View {
    @BindView(R.id.b_tab)
    TabLayout bTab;
    @BindView(R.id.b_viewpager)
    ViewPager bViewpager;

    private Presenter presenter;
    Map<String, Object> map = new HashMap<>();

    @Override
    protected int initLayoutId() {
        return R.layout.activity_classtype;
    }

    @Override
    protected void initView() {
        //实例P
        presenter = new Presenter(this);
    }

    @Override
    protected void initData() {
        //请求专业数据
        /**
         * @pageNum 页码
         * @pageSize 每页数量
         * */
        map.clear();
        map.put("pageNum", 1);
        map.put("pageSize", 4);
        presenter.onPostRequest(Api.HOME_ZHUANYE, map, ZhuanYeBean.class);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.b_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onSuccess(Object data) {
        //专业数据
        if (data instanceof ZhuanYeBean) {
            List<ZhuanYeBean.RowsBean> rows = ((ZhuanYeBean) data).getRows();
            //设置适配器
            BanXinPagerAdapter banXinPagerAdapter = new BanXinPagerAdapter(getSupportFragmentManager(), rows);
            bViewpager.setAdapter(banXinPagerAdapter);
            bTab.setupWithViewPager(bViewpager);
        }
    }

    @Override
    public void onFailure(Object error) {

    }
}
